﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SARControlLib
{
	/// <summary>
	/// TabBar.xaml 的交互逻辑
	/// </summary>
	public partial class TabBar : UserControl
	{
		public TabBar()
		{
			this.InitializeComponent();
		}

        private int currentSelectedIndex = 0;

        /// <summary>
        /// 获取当前选中的菜单项目，从0开始数
        /// </summary>
        public int SARCurrentSelectedIndex
        {
            get { return currentSelectedIndex; }
            set
            {
                currentSelectedIndex = value;
                selected1.Opacity = 0;
                selected2.Opacity = 0;
                selected3.Opacity = 0;
                selected4.Opacity = 0;
                selected5.Opacity = 0;
                selected6.Opacity = 0;
                selected7.Opacity = 0;

                txt1.FontWeight = FontWeights.Normal;
                txt1.Foreground = new SolidColorBrush(Color.FromRgb(0xa8,0xbb,0xcc));
                txt2.FontWeight = FontWeights.Normal;
                txt2.Foreground = new SolidColorBrush(Color.FromRgb(0xa8, 0xbb, 0xcc));
                txt3.FontWeight = FontWeights.Normal;
                txt3.Foreground = new SolidColorBrush(Color.FromRgb(0xa8, 0xbb, 0xcc));
                txt4.FontWeight = FontWeights.Normal;
                txt4.Foreground = new SolidColorBrush(Color.FromRgb(0xa8, 0xbb, 0xcc));
                txt5.FontWeight = FontWeights.Normal;
                txt5.Foreground = new SolidColorBrush(Color.FromRgb(0xa8, 0xbb, 0xcc));
                txt6.FontWeight = FontWeights.Normal;
                txt6.Foreground = new SolidColorBrush(Color.FromRgb(0xa8, 0xbb, 0xcc));
                txt7.FontWeight = FontWeights.Normal;
                txt7.Foreground = new SolidColorBrush(Color.FromRgb(0xa8, 0xbb, 0xcc));

                container1.Visibility = System.Windows.Visibility.Hidden;
                container2.Visibility = System.Windows.Visibility.Hidden;
                container3.Visibility = System.Windows.Visibility.Hidden;
                container4.Visibility = System.Windows.Visibility.Hidden;
                container5.Visibility = System.Windows.Visibility.Hidden;
                container6.Visibility = System.Windows.Visibility.Hidden;
                container7.Visibility = System.Windows.Visibility.Hidden;

                if (value == 0)
                {
                    selected1.Opacity = 1;
                    txt1.FontWeight = FontWeights.Bold;
                    txt1.Foreground = new SolidColorBrush(Colors.White);
                    container1.Visibility = System.Windows.Visibility.Visible;
                }
                else if (value == 1)
                {
                    selected2.Opacity = 1;
                    txt2.FontWeight = FontWeights.Bold;
                    txt2.Foreground = new SolidColorBrush(Colors.White);
                    container2.Visibility = System.Windows.Visibility.Visible;
                }
                else if (value == 2)
                {
                    selected3.Opacity = 1;
                    txt3.FontWeight = FontWeights.Bold;
                    txt3.Foreground = new SolidColorBrush(Colors.White);
                    container3.Visibility = System.Windows.Visibility.Visible;
                }
                else if (value == 3)
                {
                    selected4.Opacity = 1;
                    txt4.FontWeight = FontWeights.Bold;
                    txt4.Foreground = new SolidColorBrush(Colors.White);
                    container4.Visibility = System.Windows.Visibility.Visible;
                }
                else if (value == 4)
                {
                    selected5.Opacity = 1;
                    txt5.FontWeight = FontWeights.Bold;
                    txt5.Foreground = new SolidColorBrush(Colors.White);
                    container5.Visibility = System.Windows.Visibility.Visible;
                }
                else if (value == 5)
                {
                    selected6.Opacity = 1;
                    txt6.FontWeight = FontWeights.Bold;
                    txt6.Foreground = new SolidColorBrush(Colors.White);
                    container6.Visibility = System.Windows.Visibility.Visible;
                }
                else if (value == 6)
                {
                    selected7.Opacity = 1;
                    txt7.FontWeight = FontWeights.Bold;
                    txt7.Foreground = new SolidColorBrush(Colors.White);
                    container7.Visibility = System.Windows.Visibility.Visible;
                }
            }
        }

        /// <summary>
        /// 菜单被单击了的事件
        /// </summary>
        public event MenuClickHandler SARMenuClick;

        private void mouse1_MouseEnter(object sender, MouseEventArgs e)
        {
            if (currentSelectedIndex == 0)
            {
                return;
            }
            selected1.Opacity = 0.5;
        }

        private void mouse1_MouseLeave(object sender, MouseEventArgs e)
        {
            if (currentSelectedIndex == 0)
            {
                return;
            }
            selected1.Opacity = 0;
        }

        private void mouse1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            SARCurrentSelectedIndex = 0;
            if (SARMenuClick != null)
            {
                SARMenuClick.Invoke(0);
            }
        }

        private void mouse2_MouseEnter(object sender, MouseEventArgs e)
        {
            if (currentSelectedIndex == 1)
            {
                return;
            }
            selected2.Opacity = 0.5;
        }

        private void mouse2_MouseLeave(object sender, MouseEventArgs e)
        {
            if (currentSelectedIndex == 1)
            {
                return;
            }
            selected2.Opacity = 0;
        }

        private void mouse2_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            SARCurrentSelectedIndex = 1;
            if (SARMenuClick != null)
            {
                SARMenuClick.Invoke(1);
            }
        }

        private void mouse3_MouseEnter(object sender, MouseEventArgs e)
        {
            if (currentSelectedIndex == 2)
            {
                return;
            }
            selected3.Opacity = 0.5;
        }

        private void mouse3_MouseLeave(object sender, MouseEventArgs e)
        {
            if (currentSelectedIndex == 2)
            {
                return;
            }
            selected3.Opacity = 0;
        }

        private void mouse3_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            SARCurrentSelectedIndex = 2;
            if (SARMenuClick != null)
            {
                SARMenuClick.Invoke(2);
            }
        }

        private void mouse4_MouseEnter(object sender, MouseEventArgs e)
        {
            if (currentSelectedIndex == 3)
            {
                return;
            }
            selected4.Opacity = 0.5;
        }

        private void mouse4_MouseLeave(object sender, MouseEventArgs e)
        {
            if (currentSelectedIndex == 3)
            {
                return;
            }
            selected4.Opacity = 0;
        }

        private void mouse4_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            SARCurrentSelectedIndex = 3;
            if (SARMenuClick != null)
            {
                SARMenuClick.Invoke(3);
            }
        }

        private void mouse5_MouseEnter(object sender, MouseEventArgs e)
        {
            if (currentSelectedIndex == 4)
            {
                return;
            }
            selected5.Opacity = 0.5;
        }

        private void mouse5_MouseLeave(object sender, MouseEventArgs e)
        {
            if (currentSelectedIndex == 4)
            {
                return;
            }
            selected5.Opacity = 0;
        }

        private void mouse5_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            SARCurrentSelectedIndex = 4;
            if (SARMenuClick != null)
            {
                SARMenuClick.Invoke(4);
            }
        }
        private void mouse6_MouseEnter(object sender, MouseEventArgs e)
        {
            if (currentSelectedIndex == 5)
            {
                return;
            }
            selected6.Opacity = 0.5;
        }

        private void mouse6_MouseLeave(object sender, MouseEventArgs e)
        {
            if (currentSelectedIndex == 5)
            {
                return;
            }
            selected6.Opacity = 0;
        }

        private void mouse6_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            SARCurrentSelectedIndex = 5;
            if (SARMenuClick != null)
            {
                SARMenuClick.Invoke(5);
            }
        }
        private void mouse7_MouseEnter(object sender, MouseEventArgs e)
        {
            if (currentSelectedIndex == 6)
            {
                return;
            }
            selected7.Opacity = 0.5;
        }

        private void mouse7_MouseLeave(object sender, MouseEventArgs e)
        {
            if (currentSelectedIndex == 6)
            {
                return;
            }
            selected7.Opacity = 0;
        }

        private void mouse7_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            SARCurrentSelectedIndex = 6;
            if (SARMenuClick != null)
            {
                SARMenuClick.Invoke(6);
            }
        }
	}
}